import {
  GardenTypeItem,
  ORgListItem,
  TariffListItem,
  PropertyListItem,
  PasswordTypeItem,
} from './data.d';

function getGardenType(
  req: { url: any },
  res: {
    json: (
      arg0: { code: number, body: GardenTypeItem },
    ) => void;
  },
  u: any,
) {
  let new_url = u;
  if (!new_url || Object.prototype.toString.call(new_url) !== '[object String]') {
    new_url = req.url;
  }

  const dataSource: GardenTypeItem[] = [
    {
      codeId: 161,
      typeName: '小区类型',
      type: 134,
      codeName: '小区',
      mCode: 13401,
      codeDesc: '',
      valid: '',
      orderNo: 1,
    },
    {
      codeId: 162,
      typeName: '学校类型',
      type: 135,
      codeName: '学校',
      mCode: 13402,
      codeDesc: '',
      valid: '',
      orderNo: 2,
    },
  ];

  const result: any = {
    code: 0,
    body: dataSource,
  };

  return res.json(result);
}

function getORgList(
  req: { url: any },
  res: {
    json: (
      arg0: { code: number, body: ORgListItem },
    ) => void;
  },
  u: any,
) {
  let new_url = u;
  if (!new_url || Object.prototype.toString.call(new_url) !== '[object String]') {
    new_url = req.url;
  }

  const dataSource: ORgListItem[] = [
    { id: 1, name: '中科富创' },
    { id: 2, name: '近邻宝' },
  ];

  const result: any = {
    code: 0,
    body: dataSource,
  };

  return res.json(result);
}

function getTariffList(
  req: { url: any },
  res: {
    json: (
      arg0: { code: number, body: TariffListItem },
    ) => void;
  },
  u: any,
) {
  let new_url = u;
  if (!new_url || Object.prototype.toString.call(new_url) !== '[object String]') {
    new_url = req.url;
  }

  const dataSource: TariffListItem[] = [
    { id: 1, name: '基础套餐', valid: true },
    { id: 2, name: '五元套餐', valid: false },
    { id: 3, name: '十元套餐', valid: false },
    { id: 4, name: '二十元套餐', valid: false },
    { id: 5, name: '五十元套餐', valid: false },
  ];

  const result: any = {
    code: 0,
    body: dataSource,
  };

  return res.json(result);
}

function getPropertyList(
  req: { url: any },
  res: {
    json: (
      arg0: { code: number, body: { list: PropertyListItem, count: number} },
    ) => void;
  },
  u: any,
) {
  let new_url = u;
  if (!new_url || Object.prototype.toString.call(new_url) !== '[object String]') {
    new_url = req.url;
  }

  const dataSource: PropertyListItem[] = [
    {
      id: 1,
      createUser: 1,
      createTime: '2019-08-20',
      updateUser: 1,
      updateTime: '2019-08-20',
      createUserName: '张三丰',
      name: '宏源大厦物业',
      pinyin: 'hy',
      telephone: '13333333333',
      address: '北京北京市朝阳区酒仙桥宏源大厦',
    },
    {
      id: 2,
      createUser: 1,
      createTime: '2019-08-20',
      updateUser: 1,
      updateTime: '2019-08-20',
      createUserName: '张无忌',
      name: '天润·福熙大道物业',
      pinyin: 'hy',
      telephone: '13333333333',
      address: '北京北京市朝阳区来广营福熙大道',
    },
  ];

  const result: any = {
    code: 0,
    body: {
      list: dataSource,
      count: 20,
    },
  };

  return res.json(result);
}

function getPasswordType(
  req: { url: any },
  res: {
    json: (
      arg0: { code: number, body: PasswordTypeItem },
    ) => void;
  },
  u: any,
) {
  let new_url = u;
  if (!new_url || Object.prototype.toString.call(new_url) !== '[object String]') {
    new_url = req.url;
  }

  const dataSource: PasswordTypeItem = {
    1: '6位字母和数字',
    2: '8位纯数字',
  };

  const result: any = {
    code: 0,
    body: dataSource,
  };

  return res.json(result);
}

export default {
  'GET /code/gardenType': getGardenType,
  'GET /org/list': getORgList,
  'GET /tariff/list': getTariffList,
  'GET /property/list': getPropertyList,
  'GET /other/passwordType': getPasswordType,
};
